package com.chtmlCoder.rcc;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class inputStringOpenUrl extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getProject();
        if (project != null) {
            String userInput = Messages.showInputDialog(project, "输入关键词，按下Enter即可快速转换。", "chtml代码变量命名工具", null);
            if (userInput != null && !userInput.isEmpty()) {
                // 打开链接的逻辑
                String theUrl = "http://www.chtml.cn/w?word=" + userInput;
                // 打开URL链接
                try {
                    Desktop.getDesktop().browse(new URI(theUrl));
                } catch (IOException | URISyntaxException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }

}
